'use strict'

class  user{
  
  constructor () {

  }
  //得到用户列表
  async list (c) {
    let wuser = c.service.model.user
    let ulist = await wuser.list()
    c.send(ulist)
  }

  //得到一个用户信息
  async get (c) {
    let userid=c.param.id
    let wuser = c.service.model.user
    let ulist = await wuser.select(userid)
    c.send(ulist)
  }

  //插入数据
  async post(c){
    let {username, password, userbirth,useremail,userphone} = JSON.parse(c.body)
    let data={username,password,userbirth,useremail,userphone}
    let result = c.service.model.user
    await result.insert(data)
  }

  //删除数据
  async delete(c){
    // console.log(c.param.id)
    let wuser = c.service.model.user
    await wuser.delete(c.param.id)
  }

  //修改数据
  async put(c){
    let id=c.param.id
    let data= JSON.parse(c.body)
    let wuser =c.service.model.user
    await wuser.update(data,id)
  }
}

module.exports = user
